/*
 * Copyright (c) 2008 Benoit Bouchez, Nicolas Giard
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package com.noocodecommit.wicket.stuff.jquery.core;

import com.noocodecommit.wicket.stuff.jquery.JQOptions;

/**
 * JQAjax Option set
 * 
 * @author Benoit Bouchez
 */
public class JQAjaxOptions extends JQOptions
{
	/** datatype xml */
	public static final String DATATYPE_XML = "xml";
	/** datatype html */
	public static final String DATATYPE_HTML = "html";
	/** datatype script */
	public static final String DATATYPE_SCRIPT = "script";
	/** datatype json */
	public static final String DATATYPE_JSON = "json";
	/** datatype jsonp */
	public static final String DATATYPE_JSONP = "jsonp";
	/** datatype text */
	public static final String DATATYPE_TEXT = "text";
	/** request type GET */
	public static final String REQUESTTYPE_GET = "GET";
	/** request type POST */
	public static final String REQUESTTYPE_POST = "POST";

	private boolean async = true;
	private boolean cache = true;
	private boolean global = true;
	private boolean isModified = false;
	private boolean processData = true;
	private String contentType = "application/x-www-form-urlencoded";
	private String dataType = "";
	private String jsonp = "";
	private String password = "";
	private String scriptCharset = "";
	private String type = REQUESTTYPE_GET;
	private String url = "";
	private String username = "";
	private String xhr = "";
	private JQObject data;
	private int timeout = 0;

	private String beforeSendScript = "";
	private String completeScript = "";
	private String dataFilterScript = "";
	private String errorScript = "";
	private String successScript = "";

	/**
	 * Constructor
	 */
	public JQAjaxOptions()
	{
		super();
	}

	/**
	 * Gets the async value
	 * 
	 * @return the async value
	 */
	public boolean isAsync()
	{
		return async;
	}

	/**
	 * Sets the async option value
	 * 
	 * @param async
	 *            ajax async
	 */
	public void setAsync(boolean async)
	{
		this.async = async;
		this.options.put("async", "async:" + async);
	}

	/**
	 * Gets the cache value
	 * 
	 * @return the cache value
	 */
	public boolean isCache()
	{
		return cache;
	}

	/**
	 * Sets the cache option value
	 * 
	 * @param cache
	 *            ajax cache
	 */
	public void setCache(boolean cache)
	{
		this.cache = cache;
		this.options.put("cache", "cache:" + cache);
	}

	/**
	 * Gets the global value
	 * 
	 * @return the global value
	 */
	public boolean isGlobal()
	{
		return global;
	}

	/**
	 * Sets the global option value
	 * 
	 * @param global
	 *            ajax global
	 */
	public void setGlobal(boolean global)
	{
		this.global = global;
		this.options.put("global", "global:" + global);
	}

	/**
	 * Gets the modified value
	 * 
	 * @return the modified value
	 */
	public boolean isModified()
	{
		return isModified;
	}

	/**
	 * Sets the modified option value
	 * 
	 * @param isModified
	 *            ajax modified
	 */
	public void setModified(boolean isModified)
	{
		this.isModified = isModified;
		this.options.put("isModified", "isModified:" + isModified);
	}

	/**
	 * Gets the processData value
	 * 
	 * @return the processData value
	 */
	public boolean isProcessData()
	{
		return processData;
	}

	/**
	 * Sets the processData option value
	 * 
	 * @param processData
	 *            ajax processData
	 */
	public void setProcessData(boolean processData)
	{
		this.processData = processData;
		this.options.put("processData", "processData:" + processData);
	}

	/**
	 * Gets the content type value
	 * 
	 * @return the content type value
	 */
	public String getContentType()
	{
		return contentType;
	}

	/**
	 * Sets the contentType option value
	 * 
	 * @param contentType
	 *            ajax contentType
	 */
	public void setContentType(String contentType)
	{
		this.contentType = contentType;
		this.options.put("contentType", "contentType:'" + contentType + "'");
	}

	/**
	 * Gets the data type value
	 * 
	 * @return the data type value
	 */
	public String getDataType()
	{
		return dataType;
	}

	/**
	 * Sets the datdaType option value
	 * 
	 * @param dataType
	 *            ajax dataType
	 */
	public void setDataType(String dataType)
	{
		this.dataType = dataType;
		this.options.put("dataType", "dataType:'" + dataType + "'");
	}

	/**
	 * Gets the jsonp value
	 * 
	 * @return the jsonp value
	 */
	public String getJsonp()
	{
		return jsonp;
	}

	/**
	 * Sets the jsonp option value
	 * 
	 * @param jsonp
	 *            ajax jsonp
	 */
	public void setJsonp(String jsonp)
	{
		this.jsonp = jsonp;
		this.options.put("jsonp", "jsonp:'" + jsonp + "'");
	}

	/**
	 * Gets the password value
	 * 
	 * @return the password value
	 */
	public String getPassword()
	{
		return password;
	}

	/**
	 * Sets the password option value
	 * 
	 * @param password
	 *            ajax password
	 */
	public void setPassword(String password)
	{
		this.password = password;
		this.options.put("password", "password:'" + password + "'");
	}

	/**
	 * Gets the script charset value
	 * 
	 * @return the script charset value
	 */
	public String getScriptCharset()
	{
		return scriptCharset;
	}

	/**
	 * Sets the scriptCharset option value
	 * 
	 * @param scriptCharset
	 *            ajax script charset
	 */
	public void setScriptCharset(String scriptCharset)
	{
		this.scriptCharset = scriptCharset;
		this.options.put("scriptCharset", "scriptCharset:'" + scriptCharset + "'");
	}

	/**
	 * Gets the type value
	 * 
	 * @return the type value
	 */
	public String getType()
	{
		return type;
	}

	/**
	 * Sets the type option value
	 * 
	 * @param type
	 *            ajax type
	 */
	public void setType(String type)
	{
		this.type = type;
		this.options.put("type", "type:'" + type + "'");
	}

	/**
	 * Gets the url value
	 * 
	 * @return the url value
	 */
	public String getUrl()
	{
		return url;
	}

	/**
	 * Sets the url option value
	 * 
	 * @param url
	 *            ajax url
	 */
	public void setUrl(String url)
	{
		this.url = url;
		this.options.put("url", "url:'" + url + "'");
	}

	/**
	 * Gets the user name value
	 * 
	 * @return the user name value
	 */
	public String getUsername()
	{
		return username;
	}

	/**
	 * Sets the user name option value
	 * 
	 * @param username
	 *            ajax user name
	 */
	public void setUsername(String username)
	{
		this.username = username;
		this.options.put("username", "username:'" + username + "'");
	}

	/**
	 * Gets the xhr value
	 * 
	 * @return the xhr value
	 */
	public String getXhr()
	{
		return xhr;
	}

	/**
	 * Sets the xhr option value
	 * 
	 * @param xhr
	 *            ajax xhr
	 */
	public void setXhr(String xhr)
	{
		this.xhr = xhr;
		this.options.put("xhr", "xhr:'" + xhr + "'");
	}

	/**
	 * Gets the data value
	 * 
	 * @return the data value
	 */
	public JQObject getData()
	{
		return data;
	}

	/**
	 * Sets the data option value
	 * 
	 * @param data
	 *            ajax data
	 */
	public void setData(JQObject data)
	{
		this.data = data;
		this.options.put("data", "data:" + data);
	}

	/**
	 * Gets the timeout value
	 * 
	 * @return the timeout value
	 */
	public int getTimeout()
	{
		return timeout;
	}

	/**
	 * Sets the timeout option value
	 * 
	 * @param timeout
	 *            ajax timeout
	 */
	public void setTimeout(int timeout)
	{
		this.timeout = timeout;
		this.options.put("timeout", "timeout:" + timeout);
	}

	/**
	 * Gets the before send script value
	 * 
	 * @return the before send script value
	 */
	public String getBeforeSendScript()
	{
		return beforeSendScript;
	}

	/**
	 * Sets the before send function
	 * 
	 * @param beforeSendScript
	 *            ajax before send function
	 */
	public void setBeforeSendScript(String beforeSendScript)
	{
		this.beforeSendScript = beforeSendScript;
		this.options.put("beforeSend", "beforeSend:function (XMLHttpRequest, textStatus){" + beforeSendScript + "}");
	}

	/**
	 * Gets the complete script value
	 * 
	 * @return the complete script value
	 */
	public String getCompleteScript()
	{
		return completeScript;
	}

	/**
	 * Sets the complete function
	 * 
	 * @param completeScript
	 *            ajax complete function
	 */
	public void setCompleteScript(String completeScript)
	{
		this.completeScript = completeScript;
		this.options.put("complete", "complete:function (XMLHttpRequest){" + completeScript + "}");
	}

	/**
	 * Gets the data filter script value
	 * 
	 * @return the data filter script value
	 */
	public String getDataFilterScript()
	{
		return dataFilterScript;
	}

	/**
	 * Sets the dataFilter function
	 * 
	 * @param dataFilterScript
	 *            ajax dataFilter function
	 */
	public void setDataFilterScript(String dataFilterScript)
	{
		this.dataFilterScript = dataFilterScript;
		this.options.put("dataFilter", "dataFilter:function (data, type){" + dataFilterScript + "}");
	}

	/**
	 * Gets the error script value
	 * 
	 * @return the error script value
	 */
	public String getErrorScript()
	{
		return errorScript;
	}

	/**
	 * Sets the error function
	 * 
	 * @param errorScript
	 *            ajax error function
	 */
	public void setErrorScript(String errorScript)
	{
		this.errorScript = errorScript;
		this.options.put("error", "error:function (XMLHttpRequest, textStatus, errorThrown){" + errorScript + "}");

	}

	/**
	 * Gets the success script value
	 * 
	 * @return the success script value
	 */
	public String getSuccessScript()
	{
		return successScript;
	}

	/**
	 * Sets the success function
	 * 
	 * @param successScript
	 *            ajax success function
	 */
	public void setSuccessScript(String successScript)
	{
		this.successScript = successScript;
		this.options.put("success", "success:function (data, textStatus){" + successScript + "}");
	}

}
